package kr.co.sdworld;

import java.lang.reflect.Method;

import org.springframework.stereotype.Service;

@Injected
public class InjectionDto {
	private String name;
	private String email;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	
	
	public static void main(String[] args) {
		// xml
		String clazz = "kr.co.sdworld.InjectionDto";
		String property = "name";
		String value = "aaa";
		
		// spring
		try {
			Class cls = Class.forName(clazz);
			Object obj = cls.newInstance();
			
			if( cls.isAnnotationPresent(Injected.class)) {
				Method[] methodList = cls.getMethods();
				for (Method method : methodList) {
					String methodName = method.getName();
					property = property.substring(0,1).toUpperCase() + property.substring(1);
					
					if(methodName.startsWith("set" + property)) {
						
						//setName();
						method.invoke(obj, value);
					}
				}
				
				System.out.println(((InjectionDto)obj).getName());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
